import 'package:flutter/material.dart';
import 'package:trip_flutter/pages/LoginPage.dart';
import 'package:trip_flutter/pages/homePage.dart';

class NavigatorUtil {
  static BuildContext? _context;
  //更新context
  static upgradeContext(BuildContext context) {
    _context = context;
  }

  //跳转到任意界面
  static push(BuildContext context, Widget page) {
    Navigator.push(context, MaterialPageRoute(builder: (context) => page));
  }

  //跳转到登录目录
  static gotoLoginPage() {
    Navigator.pushReplacement(
      _context!,
      MaterialPageRoute(builder: (context) => const Loginpage()),
    );
  }

  //跳转到家目录
  static gotoHomePage(BuildContext context) async {
    if (!context.mounted) return;
    await Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => const Homepage()),
    );
  }
}
